﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Control_UpdateBusCarControl : System.Web.UI.UserControl
{
    ListAndProcessData ws = new ListAndProcessData();
    private string getid = null;
    private int id;
    private string getbusno = null;
    private string getseatused = null;
    private string getslocation = null;
    private string getelocation = null;
    private string gettype = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        getid = Request.QueryString["idbuscar"].ToString();
        if (!IsPostBack)
        {
            gettype = Request.QueryString["bustype"].ToString();
            getbusno = Request.QueryString["Busno"].ToString();
            getseatused = Request.QueryString["Seatuse"].ToString();
            getslocation = Request.QueryString["slocation"].ToString();
            getelocation = Request.QueryString["elocation"].ToString();

            txtBusNo.Text = getbusno;
            txtSeatsUsed.Text = getseatused;
            var a = ws.getTravelPlan();
            var b = ws.getSLocation();
            foreach (var item in b)
            {
                DropDownListstartLocatioon.Items.Add(item.Startlocaion);
            }
            foreach (var item in a)
            {
           
                
                
                DropDownList1.Items.Add(item.EndLocation);
            }
            var c = ws.getBusType();
            foreach (var item1 in c)
            {
                DropDownListBusType.Items.Add(item1.Name);
            }

            DropDownList1.SelectedValue = getelocation;
            DropDownListBusType.SelectedValue = gettype;
            DropDownListstartLocatioon.SelectedValue = getslocation;
        }    
         
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        getid = Request.QueryString["idbuscar"].ToString();
        int idcar = Convert.ToInt32(getid);
        string busno = txtBusNo.Text;
        string seatused = txtSeatsUsed.Text;
        bool a = false;
        a = ws.UpdateBusCar(idcar, busno, seatused, (DropDownListstartLocatioon.SelectedItem).ToString(), (DropDownListBusType.SelectedItem).ToString(), (DropDownList1.SelectedItem).ToString());
        if (a == true)
        {
            Response.Redirect("../Admin/ShowBusCar_Admin.aspx");

        }
        else
        {
           Response.Redirect("Default3.aspx");
        }
    
    }
    protected void btnreset_Click(object sender, EventArgs e)
    {
        txtBusNo.Text = "";
        txtSeatsUsed.Text = "";
        DropDownListstartLocatioon.SelectedIndex = 0;
        DropDownListBusType.SelectedIndex = 0;
        DropDownList1.SelectedIndex = 0;
    }
    protected void DropDownListstartLocatioon_SelectedIndexChanged(object sender, EventArgs e)
    {
        var d = ws.getEndLocation((DropDownListstartLocatioon.SelectedItem).ToString());
        DropDownList1.Items.Clear();
        foreach (var item in d)
        {
            DropDownList1.Items.Add(item.Location);
        }
    }
}